[#include "/main/mainTemplate.ftl"]
[@main title="wdTree 树结构使用Demo"]

[#-- 树构建 --]
<div style="margin-bottom:5px;">
	<a class="button" href="javascript:void(0);" id="showchecked">获取选择的节点编号</a>
	<a class="button" href="javascript:void(0);" id="showcurrent">获取当前节点编号</a>
	[#--<a class="button" href="javascript:void(0);" id="reflashnode0">Refresh root-0</a>--]
</div>

<div style="border-bottom: #c3daf9 1px solid; border-left: #c3daf9 1px solid; width: 250px; height: 500px; overflow: auto; border-top: #c3daf9 1px solid; border-right: #c3daf9 1px solid;">
	<div id="tree"></div>        
</div>

<script type="text/javascript">
var child = 
{
    "id" : "1",
    "text" : "aa",
    "value" : "1087",
    "showcheck" : true,
    complete : true,
    "isexpand" : true,
    "checkstate" : 0,
    "hasChildren" : false
  };  
  
  var root = 
	{
    	"id" : "0",
        "text" : "节点一",
        "value" : "1086",
        "showcheck" : true,// 是否打开 checkbox 按钮
        complete : true, // 是否异步请求 true:同步
        "isexpand" : true,// 是否展开
        "checkstate" : 0,
        "hasChildren" : true, // 如果存在子节点设置为 true, 不存在设置为 false
        "ChildNodes": [child]
  };
  
//root.ChildNodes = [child];

  
  // 异步处理
  function ajaxData(data) {
  	
  	data = data.value;
  	
  	var arr = [];
  	var len = data.length;
  	if (len > 0) {
  		for (var i = 0; i < len; i++) {
  			arr.push({
			    "id" : '' + data[i].columnId,
			    "text" : '' + data[i].columnName,
			    "value" : "86",
			    "showcheck" : true,
			    complete : false,
			    "isexpand" : false,
			    "checkstate" : 0,
			    "hasChildren" : true
			});
  		}
  	}
  	
  	return arr;
  }

        var userAgent = window.navigator.userAgent.toLowerCase();
        $.browser.msie8 = $.browser.msie && /msie 8\.0/i.test(userAgent);
        $.browser.msie7 = $.browser.msie && /msie 7\.0/i.test(userAgent);
        $.browser.msie6 = !$.browser.msie8 && !$.browser.msie7 && $.browser.msie && /msie 6\.0/i.test(userAgent);
        
        function load() {        
            var o = { 
            	showcheck: true
            	//url: "../demo/add"
            };
            o.data = [root];      
            o.cbiconpath = "../wdTree/css/images/icons/"            
            $("#tree").treeview(o);   
                     
            // 获取选中节点的id
            $("#showchecked").click(function(e){
                var s=$("#tree").getCheckedNodes();
                if(s !=null) {
                	alert(s.join(","));
                } else {
                	alert("NULL");
                }
            });
            
            // 获取选中的当前节点id
             $("#showcurrent").click(function(e){
                var s=$("#tree").getCurrentNode();
                alert(s.value);
                if(s !=null)
                    alert(s.text);
                else
                    alert("NULL");
             });
        } 
        
        if($.browser.msie6)
        {
            load();
        }
        else
        {
            $(document).ready(load);
        }
        
    </script>
[/@main]